home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / ULP2mos2.asm < prev    next >
Encoding:
Assembly Source File  |  2001-02-27  |  4.8 KB  |  203 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11.  
  12.  
  13. #    f0        volatile
  14. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  15. #    f5  .. f13    volatile, pass 5th - 13th float args
  16. #    f14 .. f31    saved
  17.  
  18. #    Use r22 as Color
  19. #    Use r23    as CurCnt
  20. #    Use r24    as MaxCnt (Constant value)
  21. #    Use r25    as LPixelBuf
  22. #    Use r26    as location within ColorTable32
  23. #    Use r27    as base address of ColorTable32
  24. #    Use r28    as BPP (that is, bytes per pixel)
  25.  
  26. #    r29    as RightEdge
  27. #    r30    as xtemp (integer)
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #    Note that the following are constants, and independent of xtemp.
  34.  
  35. #    First the integers
  36. #    MaxCnt    in r24
  37. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  38. #    Base address of ColorTable32 in r27
  39. #    BPP in r28
  40.  
  41. #    Now the floats    (Newly defined)
  42.  
  43.  
  44. #    xRel in f15 (changes as DX is added in on each pass)
  45. #    Use f16    as value of yRel.  This is constant for each line.
  46. #    Use f17    as value that was stored in 40(r1).  It's Zi
  47. #    Use f18    as Zr.
  48. #    Use f19 as |Zr2| + |Zi2|    Only for comparing with Limit.
  49. #    Use f20    This is scratch and used shortly for 2Zi.
  50. #    Delta x    in f21
  51. #    Two    in f22
  52. #    Limit    in f23
  53. #    Use f24    as Zr2.  This is also a temporary value
  54.  
  55.  
  56. #vsc elf
  57.     .text
  58.     .sdreg    13
  59.     .global    UseLibP2
  60.     .align    4
  61. UseLibP2:
  62.     mflr    11
  63.     stw    11,4(1)    #Save return address
  64.     stwu    1,-80(1)      #Save stack pointer
  65.     fmr    16,1        #Transfer yrel from f1 to f16
  66.  
  67.     lis    11,Color@ha
  68.     lwz    22,Color@l(11)
  69.     lis    11,MaxCnt@ha
  70.     lwz    24,MaxCnt@l(11)    #MaxCnt in r24.
  71.     lis    11,LPixelBuf@ha
  72.     lwz    25,LPixelBuf@l(11)    #Get Location of LPixelBuf
  73.     lis    11,ColorTable32@ha
  74.     lwz    27,ColorTable32@l(11)    #Start of color table
  75.     lis    11,BPP@ha
  76.     lwz    28,BPP@l(11)             #Number bytes per pixel
  77.     lis    11,Factor@ha
  78.     lfd    25,Factor@l(11)    #Get Factor into f25
  79.     lis    11,Two@ha
  80.     lfd    22,Two@l(11)    #Get Two into f22 as constant
  81.     lis    11,Limit@ha
  82.     lfd    23,Limit@l(11)    #Get Limit into f23 as constant
  83.  
  84.     li    30,0        #xtemp = 0.
  85. # Convert xtemp to double fp.
  86.     lis    12,17200    #r12 = 0x4330
  87.  
  88.     lis    11,.l14@ha
  89.     stw    12,.l14@l(11)    #Place in buffer
  90.  
  91.     xoris    12,30,32768   #XOR with 0x8000
  92.  
  93.     lis    18,.l15@ha
  94.     stw    12,.l15@l(18)     #Store in high word of buffer
  95.  
  96.  
  97.     lis    11,.l14@ha
  98.     lfd    0,.l14@l(11)      #Get back as double
  99.  
  100.     lis    11,.l13@ha
  101.     lfd    10,.l13@l(11)
  102.     fsub    15,0,10        #Find (double)xtemp
  103.     lis    11,XCenter@ha
  104.     lfd    10,XCenter@l(11)    #f10 = XCenter
  105.     fsub    15,15,10    #xRel = xRel - XCenter
  106.     fdiv    15,15,25    #xRel = xRel/Factor
  107.     lis    11,DX@ha
  108.     lfd    21,DX@l(11)    #Get the real value of Delta x.
  109.     lis    11,RightEdge@ha
  110.     lwz    29,RightEdge@l(11)
  111.  
  112. Start:
  113.     fmr    18,15        #Initial value of Zr is xRel.
  114. #  The following line was moved before rather than after fmr f17,f16
  115. #  to give the fpu a break.
  116.     li    23,1        #Initialize CurCnt = 1
  117.     fmr    17,16        #yRel into f17 as initial Zi.
  118.     b    l3        #Check to see if to MaxCnt
  119. l2:    fmul    24,18,18    #Zr2 in f24
  120.     fmul    4,17,17        #Zi2 = Zi*Zi
  121.     fadd    19,24,4
  122.     fcmpu    0,19,23        #Compare with Limit in f23.
  123.     ble    0,l6
  124.  
  125. #The following section is not very time-critical as it is only reached once.
  126. #for each pixel
  127.     cmpwi    0,28,2        #See if BPP < 2
  128.     blt    0,l8
  129. l7:
  130.     slwi    10,23,2        #4 times CurCnt for offset in ColorTable32
  131.     add    26,27,10    #Find location of pixel color in ColorTable32
  132.     lwz    11,0(26)    #Get ARGB from ColorTable
  133.     stw    11,0(25)    #Store color in LPixelBuf
  134.     addi    25,25,4        #Point to next location in LPixelBuf
  135.     b    l1
  136. l8:    andi.    0,23,65535    #Prep for storage as UWORD
  137.     sth    0,0(22)       #Store in _Color
  138.     bl    PlotIt
  139. l9:    b    l1
  140. l6:
  141.     fmul    20,22,17    #Find 2*Zi (Two in f22)
  142.     fsub    10,24,4      #Zr2 = Zr2 - Zi2
  143.     fmul    17,20,18    #Find 2*Zi*Zr (temporary Zi)
  144.     addi    23,23,1       #Increment CurCnt
  145.     fadd    18,15,10    #New Zr = xRel + Zr2
  146.     fadd    17,16,17    #Zi = Zi + yRel
  147. l3:
  148.     cmpw    0,23,24        #See if CurCnt < MaxCnt
  149.     blt    0,l2        #Repeat until MaxCnt reached
  150.  
  151.     cmpwi    0,28,2        #See if BPP < 2
  152.     blt    0,l11
  153. l10:
  154.  
  155.     lis    12,4
  156.     addi    12,12,-4
  157.     add    26,27,12    #Find location of pixel color
  158.     lwz    11,0(26)      #Get color
  159.  
  160.     stw    11,0(25)    #Store color in LPixelBuf
  161.     addi    25,25,4        #Point to next pixel in buffer
  162.     b    l1        #Was l12
  163. l11:
  164.     lis    11,1
  165.     addi    11,11,-1
  166.     sth    11,0(22)    #Store in _Color
  167.     bl    PlotIt
  168. l1:
  169.     fadd    15,15,21    #Find new value of xRel.
  170.     addi    30,30,1        #Increment xtemp.
  171.     cmpw    0,30,29        #See if to RightEdge
  172.  
  173.     blt    0,Start        #Repeat until row is done.
  174.     lis    11,LPixelBuf@ha
  175.     stw    25,LPixelBuf@l(11)  #New location in long pixel buffer
  176.     addi    1,1,80            #Balance Stack pointer
  177.     lwz    11,4(1)        #Get return address
  178.     mtlr    11
  179.     blr
  180.     .type    UseLibP2,@function
  181.     .size    UseLibP2,$-UseLibP2
  182.  
  183.     .globl    MaxCnt
  184.     .globl    RightEdge
  185.     .globl    XCenter
  186.     .globl    Factor
  187.     .globl    Limit
  188.     .globl    Two
  189.     .globl    Color
  190.     .globl    LPixelBuf
  191.     .globl    ColorTable32
  192.     .globl    BPP
  193.     .globl    DX
  194.     .globl    PlotIt
  195.  
  196.     .section .rodata
  197.     .align    2
  198.     .align    3
  199. .l13:
  200.     .long    0x43300000,0x80000000
  201. .l14:    .word    0
  202. .l15:    .word    0,0,0
  203.